package com.house365.core.helper;

import java.util.List;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

import com.house365.core.bean.VersionInfo;
import com.house365.core.constant.CorePreferences;
import com.house365.core.util.FileUtil;

public class PackageHelper {

	private ProgressDialog mProgress = null;
	private Context mContext = null;

	public PackageHelper(Context context) {
		this.mContext = context;
	}

	public static boolean isInstalledApp(Context context, String packagename) {
		PackageManager manager = context.getPackageManager();
		List<PackageInfo> pkgList = manager.getInstalledPackages(0);
		for (int i = 0; i < pkgList.size(); i++) {
			PackageInfo pI = pkgList.get(i);
			if (pI.versionName == null) {
				continue;
			}
			if (pI.packageName.startsWith(packagename)) {
				return true;
			}
		}
		return false;
	}

	//
	public static void installApk(Context context, String apkfile) {
		// ����ļ����� ��ֱ�Ӱ�װ
		if (FileUtil.isExistFile(apkfile)) {
			//IntentUtil.openFileByType(context, new File(apkfile));
		}
	}

 

	/**
	 * ��ȡ��ǰ�汾��Ϣ
	 */
	public static VersionInfo getCurrentVersion(Context context) {
		try {
			PackageInfo info = context.getPackageManager().getPackageInfo(
					context.getPackageName(), 0);
			VersionInfo version = new VersionInfo();
			version.versionCode = info.versionCode;
			version.versionName = info.versionName;
			CorePreferences.DEBUG("��ǰ�汾��" + version.versionCode);
			return version;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}
}
